<script setup lang="ts">
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
import zhCn from 'element-plus/lib/locale/lang/zh-cn'
import { TokenHandler } from '@/utils/token'
import API from '@/api'
const locale = zhCn
const obj = reactive({
  params: {
    Password: '123456',
    UserName: 'vehicle',
  },
})
API.token.ssoToken(obj.params).then((res) => {
  // console.log('res', res)
  let { access_token, expires_in, refresh_token } = res
  TokenHandler.setToken(access_token, expires_in)
  TokenHandler.setRefreshToken(refresh_token)
})
const fnRefreshToken = () => {
  let refreshToken = TokenHandler.getRefreshToken()
  let params = { RefreshToken: refreshToken }
  API.token.refreshSsotoken(params).then((res) => {
    console.log('fnRefreshToken', res)
    let { access_token, expires_in, refresh_token } = res
    TokenHandler.setToken(access_token, expires_in)
    TokenHandler.setRefreshToken(refresh_token)
  })
}
// 15分钟重载一次
const { pause, resume } = useIntervalFn(() => {
  fnRefreshToken()
}, 15*60*1000)
onMounted(() => {
  resume()
})
onUnmounted(() => {
  pause()
})
</script>

<template>
  <el-config-provider :locale="zhCn">
    <router-view />
  </el-config-provider>
</template>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
</style>
